Everything about Object Orientation totally explained
Object-oriented programming (OOP) is a
programming paradigm that uses "
objects" and their interactions to design applications and computer programs. Programming techniques may include features such as
encapsulation,
modularity,
polymorphism, and
inheritance. It wasn't commonly used in mainstream software application development until the early 1990s. Many modern
programming languages now support OOP.
Introduction
Object-oriented programming can trace its roots to the 1960s. As hardware and software became increasingly complex, researchers studied ways in which software quality could be maintained. Object-oriented programming was deployed in part as an attempt to address this problem by strongly emphasizing discrete units of programming logic and re-usability in software.
The
Simula programming language was the first to introduce the concepts underlying object-oriented programming (objects, classes, subclasses, virtual methods, coroutines, garbage collection, and discrete event simulation) as a superset of
Algol. Simula was used for physical modeling, such as models to study and improve the movement of ships and their content through cargo ports.
Smalltalk was the first programming language to be called "object-oriented".
Object-oriented programming may be seen as a collection of cooperating
objects, as opposed to a traditional view in which a program may be seen as a group of tasks to compute ("
subroutines"). In OOP, each object is capable of receiving messages, processing data, and sending messages to other objects.
Each object can be viewed as an independent little machine with a distinct role or responsibility. The actions or "
operators" on the objects are closely associated with the object. For example, in OOP, the
data structures tend to carry their own operators around with them (or at least "inherit" them from a similar object or "class"). The traditional approach tends to view and consider data and behavior separately.
Fundamental concepts
A survey by Deborah J. Armstrong of nearly 40 years of computing literature identified a number of ‘quarks’, or fundamental concepts, found in the strong majority of definitions of OOP. They are the following:
Class : Defines the abstract characteristics of a thing (object), including the thing's characteristics (its attributes, fields or properties) and the thing's behaviors (the things it can do, or methods, operations or features). One might say that a class is a blueprint or factory that describes the nature of something. For example, the class Dog would consist of traits shared by all dogs, such as breed and fur color (characteristics), and the ability to bark and sit (behaviors). Classes provide modularity and structure in an object-oriented computer program. A class should typically be recognizable to a non-programmer familiar with the problem domain, meaning that the characteristics of the class should make sense in context. Also, the code for a class should be relatively self-contained (generally using encapsulation). Collectively, the properties and methods defined by a class are called members.
; Object : A particular object. The class of Dog defines all possible dogs by listing the characteristics and behaviors they can have; the object Lassie is one particular dog, with particular versions of the characteristics. A Dog has fur; Lassie has brown-and-white fur.
Instance : One can have an instance of a class or a particular object. The instance is the actual object created at runtime. In programmer jargon, the Lassie object is an instance of the Dog class. The set of values of the attributes of a particular object is called its state. The object consists of state and the behaviour that's defined in the object's class.
; Method : An object's abilities. In language, methods are verbs. Lassie, being a Dog, has the ability to bark. So bark is one of Lassie's methods. She may have other methods as well, for example sit or eat or walk. Within the program, using a method usually affects only one particular object; all Dogs can bark, but you need only one particular dog to do the barking.
Message passing : “The process by which an object sends data to another object or asks the other object to invoke a method.”
Not all of the above concepts are to be found in all object-oriented programming languages, and so object-oriented programming that uses classes is called sometimes class-based programming. In particular, prototype-based programming doesn't typically use classes. As a result, a significantly different yet analogous terminology is used to define the concepts of object and instance, although there are no objects in these languages.
History
The concept of objects and instances in computing had its first major breakthrough with the
PDP-1 system at
MIT which was probably the earliest example of capability based architecture. Another early
example was
Sketchpad made by
Ivan Sutherland in 1963; however, this was an application and not a
programming paradigm.
Objects as programming entities were introduced in the 1960s in
Simula 67, a programming language designed for making simulations, created by
Ole-Johan Dahl and
Kristen Nygaard of the
Norwegian Computing Center in
Oslo. (Reportedly, the story is that they were working on ship simulations, and were confounded by the combinatorial explosion of how the different attributes from different ships could affect one another. The idea occurred to group the different types of ships into different classes of objects, each class of objects being responsible for defining its
own data and
behavior.) Such an approach was a simple extrapolation of concepts earlier used in
analog programming. On
analog computers, such direct mapping from real-world phenomena/objects to analog phenomena/objects (and conversely), was (and is) called 'simulation'. Simula not only introduced the notion of classes, but also of instances of classes, which is probably the first explicit use of those notions. The ideas of
Simula 67 influenced many later languages, especially Smalltalk and derivatives of
Lisp and
Pascal.
The
Smalltalk language, which was developed at
Xerox PARC in the 1970s, introduced the term
Object-oriented programming to represent the pervasive use of objects and messages as the basis for computation.
Smalltalk creators were influenced by the ideas introduced in
Simula 67, but
Smalltalk was designed to be a fully dynamic system in which classes could be created and modified dynamically rather than statically as in
Simula 67. Smalltalk and with it OOP were introduced to a wider audience by the August 1981 issue of
Byte magazine.
In the 1980s, there were a few attempts to design processor architectures which included hardware support for objects in memory but these were not successful. Examples include the
Intel iAPX 432 and the
Linn Smart Rekursiv.
Object-oriented programming developed as the dominant programming methodology during the mid-1990s, largely due to the influence of
C++. Its dominance was further cemented by the rising popularity of
graphical user interfaces, for which object-oriented programming is well-suited. An example of a closely related dynamic GUI library and OOP language can be found in the
Cocoa frameworks on
Mac OS X, written in
Objective C, an object-oriented, dynamic messaging extension to C based on Smalltalk. OOP toolkits also enhanced the popularity of
event-driven programming (although this concept isn't limited to OOP). Some feel that association with GUIs (real or perceived) was what propelled OOP into the programming mainstream.
At
ETH Zürich,
Niklaus Wirth and his colleagues had also been investigating such topics as
data abstraction and
modular programming.
Modula-2 included both, and their succeeding design,
Oberon, included a distinctive approach to object orientation, classes, and such. The approach is unlike Smalltalk, and very unlike C++.
Object-oriented features have been added to many existing languages during that time, including
Ada,
BASIC,
Lisp,
Fortran,
Pascal, and others. Adding these features to languages that were not initially designed for them often led to problems with compatibility and maintainability of code.
In the past decade
Java has emerged in wide use partially because of its similarity to
C and to
C++, but perhaps more importantly because of its implementation using a
virtual machine that's intended to run code unchanged on many different platforms. This last feature has made it very attractive to larger development shops with heterogeneous environments. Microsoft's
.NET initiative has a similar objective and includes/supports several new languages, or variants of older ones.
More recently, a number of languages have emerged that are primarily object-oriented yet compatible with procedural methodology, such as
Python and
Ruby. Besides Java, probably the most commercially important recent object-oriented languages are
Visual Basic .NET (VB.NET) and
C#, both designed for Microsoft's
.NET platform. VB.NET and C# both support cross-language inheritance, allowing classes defined in one language to subclass classes defined in the other language.
Recently many universities have begun to teach Object-oriented design in introductory computer science classes.
Just as
procedural programming led to refinements of techniques such as
structured programming, modern object-oriented software design methods include refinements such as the use of
design patterns,
design by contract, and
modeling languages (such as
UML).
OOP in scripting
In recent years, object-oriented programming has become especially popular in
scripting programming languages.
Python and
Ruby are scripting languages built on OOP principles, while
Perl and
PHP have been adding object oriented features since Perl 5 and PHP 4, and
ColdFusion since version 6.
The
Document Object Model of
HTML,
XHTML, and
XML documents on the Internet have bindings to the popular
JavaScript/
ECMAScript language. JavaScript is perhaps the best known
prototype-based programming language which employs cloning from prototypes rather than inheriting from a class.
ActionScript also uses an Object-oriented approach and is just like JavaScript based on ECMAScript.
Problems and patterns
There are a number of programming challenges which a developer encounters regularly in object-oriented design. There are also widely accepted solutions to these problems. The best known are the
design patterns codified by Gamma et al, but in a broader sense the term "
design patterns" can be used to refer to any general, repeatable solution to a commonly occurring problem in software design. Some of these commonly occurring problems have implications and solutions particular to object-oriented development.
Gang of Four design patterns
Design Patterns: Elements of Reusable Object-Oriented Software is an influential book published in 1995 by
Erich Gamma,
Richard Helm,
Ralph Johnson, and
John Vlissides, sometimes casually called the "Gang of Four." Along with exploring the capabilities and pitfalls of object-oriented programming, it describes 23 common programming problems and patterns for solving them.
As of April 2007, the book was in its 36th printing.
Typical design patterns are as follows:
Object-orientation and databases
Both object-oriented programming and
relational database management systems (RDBMSs) are extremely common in software
today. Since
relational databases don't store objects directly (though some RDBMSs have object-oriented features to approximate this), there's a general need to bridge the two worlds. There are a number of widely used solutions to this problem. One of the most common is
object-relational mapping, as found in libraries like
Java Data Objects, and
Ruby on Rails' ActiveRecord.
There are also
object databases which can be used to replace RDBMSs, but these have not been as commercially successful as RDBMSs.
Matching real world
OOP can be used to translate from real-world phenomena to program elements (and vice versa). OOP was even invented for the purpose of physical modeling in the
Simula-67 programming language. However, not everyone agrees that direct real-world mapping is facilitated by OOP, or is even a worthy goal;
Bertrand Meyer argues in
Object-Oriented Software Construction that a program isn't a model of the world but a model of some part of the world; "Reality is a cousin twice removed". At the same time, some principal limitations of OOP had been noted.
Niklaus Wirth said of OOP in his paper "Good Ideas through the Looking Glass", "This paradigm closely reflects the structure of systems 'in the real world', and it's therefore well suited to model complex systems with complex behaviour."
Formal definition
There have been several attempts at formalizing the concepts used in object-oriented programming. The following concepts and constructs have been used as interpretations of OOP concepts:
coalgebraic datatypes
existential quantification and modules
recursion
records and record extensions
F-bounded polymorphism
Attempts to find a consensus definition or theory behind objects have not proven very successful (however, see "Abadi & Cardelli: A Theory of Objects" for formal definitions of many OO concepts and constructs), and often diverge widely. For example, some definitions focus on mental activities, and some on mere program structuring. One of the simpler definitions is that OOP is the act of using "map" data structures or arrays that can contain functions and pointers to other maps, all with some syntactic and scoping sugar on top. Inheritance can be performed by cloning the maps (sometimes called "prototyping").
Criticism
Richard Stallman wrote in 1995, "Adding OOP to Emacs isn't clearly an improvement; I used OOP when working on the Lisp Machine window systems, and I disagree with the usual view that it's a superior way to program."
A study by Potok et al. has shown no significant difference in productivity between OOP and procedural approaches.
Christopher J. Date stated that critical comparison of OOP to other technologies, relational in particular, is difficult because of lack of an agreed-upon and rigorous definition of OOP.
Alexander Stepanov suggested that OOP provides a mathematically-limited viewpoint and called it, "almost as much of a hoax as Artificial Intelligence" (possibly referring to the Artificial Intelligence projects and marketing of the 1980s that are sometimes viewed as overzealous in retrospect).
Edsger W. Dijkstra wrote:
... what society overwhelmingly asks for is snake oil. Of course, the snake oil has the most impressive names —otherwise you'd be selling nothing— like "Structured Analysis and Design", "Software Engineering", "Maturity Models", "Management Information Systems", "Integrated Project Support Environments" "Object Orientation" and "Business Process Re-engineering" (the latter three being known as IPSE, OO and BPR, respectively)." — EWD 1175: The strengths of the academic enterprise
Further Information
Get more info on 'Object Orientation'.
|
External Link Exchanges
Do you know how hard it is to get a link from a large encyclopaedia? Well we're different and will prove it. To get a link from us just add the following HTML to your site on a relevant page:
<a href="http://object-oriented_programming.totallyexplained.com">Object-oriented programming Totally Explained</a>
Then simply click through this link from your web page. Our crawlers will verify your link, extract the title of your web page and instantly add a link back to it. If you like you can remove the words Totally Explained and embed the link in article text.
As long as your link remains in place, we'll keep our link to you right here. Please play fair - our crawlers are watching. Your site must be closely related to this one's topic. Any kind of spamming, dubious practises or removing the link will result in your link from us being dropped and, potentially, your whole site being banned. |